/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić                    *
 *   ivasic@gmail.com                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef EXHANDLER_H
#define EXHANDLER_H

#include <QObject>
#include <QMutex>

class QThread;
class Exception;
class ExceptionManager;

/**
 * @interface ExHandler
 * @brief Interfejs za ExceptionHandler.
 * 
 * Sadrži objekat ExceptionManager  i služi kao fasada za Error Handling Framework.
 * Implementacija bi trebalo da bude Singleton klasa.
 * 
 * Svaki uhvaćeni izuzetak bi po pravilu trebalo da se preda implementaciji ovog objekta (ExceptionHandler-u) koji poziva roditeljsku metodu protocolException. Ova metoda prosledjuje poruku Loggeru ako je potrebno i na kraju BRIŠE objekat Exception!<br> Ukoliko Exception ne bude prosledjen, mora biti 'ručno' obrisan po upotrebi. Ova klasa to radi automatski tako da je bolje to koristiti.
 * 
 * @author Ivan Vasić <ivasic@gmail.com>
*/

class ExHandler : public QObject
{
		Q_OBJECT

	public:
		ExHandler(QObject *parent = 0);
		virtual ~ExHandler();
		
		/**
		 * @brief Prosledjuje izuzetak ExceptionManager-u.
		 * 
		 * Klasa koja nasledi ovaj interfejs treba da implementira ovaj metod za obradu izuzetka.
		 * Da bi se ovaj metod delegirao ExceptionManager-u u nasledjenoj klasi @e obavezno pozvati roditeljski metod.
		 */
		virtual void protocolException(const QThread* id, Exception* ex, bool log = true);
				
	protected:
//		static QMutex m_mutex;
		
	private:
		
		///ExceptionManager pointer.
		ExceptionManager* m_manager;
};

#endif
